import { http } from '@/utils/http';
// 用户认证相关API
export const authApi = {
  // 用户登录
  login: (credentials) => http.post('/security/sec-auth/login', credentials),
  
  // 获取当前用户信息
  getCurrentUser: () => http.get('/authority/self'),
  
  // 用户注销
  logout: () => http.post('/authority/logout'),
  
  // 刷新token
  refreshToken: (refreshToken) => http.post('/authority/refresh', { refreshToken }),
  
  // 修改密码
  changePassword: (passwordData) => http.post('/security/sec-user/change-password', passwordData),
};

// 用户管理API
export const userApi = {
  // 获取用户列表
  getUsers: (params) => http.get('/users', params),
  
  // 获取用户详情
  getUser: (userId) => http.get(`/users/${userId}`),
  
  // 创建用户
  createUser: (userData) => http.post('/users', userData),
  
  // 更新用户
  updateUser: (userId, userData) => http.put(`/users/${userId}`, userData),
  
  // 删除用户
  deleteUser: (userId) => http.delete(`/users/${userId}`),
  
  // 批量删除用户
  batchDeleteUsers: (userIds) => http.post('/users/batch-delete', { userIds }),
  
  // 获取个人信息
  getSelfInfo: () => http.get('/security/sec-user/self'),
};

// 角色权限API
export const roleApi = {
  // 获取角色列表
  getRoles: (params) => http.get('/roles', params),
  
  // 获取角色详情
  getRole: (roleId) => http.get(`/roles/${roleId}`),
  
  // 创建角色
  createRole: (roleData) => http.post('/roles', roleData),
  
  // 更新角色
  updateRole: (roleId, roleData) => http.put(`/roles/${roleId}`, roleData),
  
  // 删除角色
  deleteRole: (roleId) => http.delete(`/roles/${roleId}`),
  
  // 获取权限列表
  getPermissions: () => http.get('/permissions'),
  
  // 分配角色权限
  assignPermissions: (roleId, permissionIds) => http.put(`/roles/${roleId}/permissions`, { permissionIds }),
  
  // 获取当前用户的角色列表
  getSelfRoles: () => http.get('/security/sec-role/self'),
  
  // 切换当前用户的角色
  switchRole: (roleId) => http.post(`/security/sec-role/switch/${roleId}`),
};

// 文件管理API
export const fileApi = {
  // 获取文件列表
  getFiles: (params) => http.get('/files', params),
  
  // 获取文件详情
  getFile: (fileId) => http.get(`/files/${fileId}`),
  
  // 上传文件
  uploadFile: (file, options = {}) => http.upload('/files/upload', file, options),
  
  // 删除文件
  deleteFile: (fileId) => http.delete(`/files/${fileId}`),
  
  // 批量删除文件
  batchDeleteFiles: (fileIds) => http.post('/files/batch-delete', { fileIds }),
  
  // 移动文件
  moveFile: (fileId, targetPath) => http.put(`/files/${fileId}/move`, { targetPath }),
  
  // 复制文件
  copyFile: (fileId, targetPath) => http.post(`/files/${fileId}/copy`, { targetPath }),
  
  // 重命名文件
  renameFile: (fileId, newName) => http.put(`/files/${fileId}/rename`, { newName }),
  
  // 获取文件分享链接
  shareFile: (fileId, shareOptions) => http.post(`/files/${fileId}/share`, shareOptions),
  
  // 获取共享文件列表
  getSharedFiles: (params) => http.get('/files/shared', params),
  
  // 获取已加星标文件
  getStarredFiles: (params) => http.get('/files/starred', params),
  
  // 添加/移除星标
  toggleStar: (fileId) => http.put(`/files/${fileId}/star`),
  
  // 删除文件或目录
  removeFiles: (fileKeyList) => http.post('/storage/stg-file/remove', { fileKeyList }),
  
  // 重命名文件或目录
  renameFileOrDirectory: (fileKey, newFileName) => http.post('/storage/stg-file/rename', { fileKey, newFileName }),
};

// 系统配置API
export const systemApi = {
  // 获取系统配置
  getConfig: () => http.get('/system/config'),
  
  // 更新系统配置
  updateConfig: (config) => http.put('/system/config', config),
  
  // 获取系统状态
  getStatus: () => http.get('/system/status'),
  
  // 获取系统日志
  getLogs: (params) => http.get('/system/logs', params),
};

// 存储源API
export const storageApi = {
  // 获取存储源列表
  getSources: (params) => http.get('/storage/sources', params),
  
  // 获取存储源详情
  getSource: (sourceId) => http.get(`/storage/sources/${sourceId}`),
  
  // 创建存储源
  createSource: (sourceData) => http.post('/storage/sources', sourceData),
  
  // 更新存储源
  updateSource: (sourceId, sourceData) => http.put(`/storage/sources/${sourceId}`, sourceData),
  
  // 删除存储源
  deleteSource: (sourceId) => http.delete(`/storage/sources/${sourceId}`),
  
  // 测试存储源连接
  testConnection: (sourceId) => http.post(`/storage/sources/${sourceId}/test`),
  
  // 获取存储统计
  getStorageStats: () => http.get('/storage/stats'),
};

// API管理相关
export const apiManagementApi = {
  // 获取API列表
  getApis: (params) => http.get('/api-management/apis', params),
  
  // 获取API详情
  getApi: (apiId) => http.get(`/api-management/apis/${apiId}`),
  
  // 创建API
  createApi: (apiData) => http.post('/api-management/apis', apiData),
  
  // 更新API
  updateApi: (apiId, apiData) => http.put(`/api-management/apis/${apiId}`, apiData),
  
  // 删除API
  deleteApi: (apiId) => http.delete(`/api-management/apis/${apiId}`),
  
  // 测试API
  testApi: (apiId, testData) => http.post(`/api-management/apis/${apiId}/test`, testData),
  
  // 获取API调用统计
  getApiStats: (apiId) => http.get(`/api-management/apis/${apiId}/stats`),
};

// 导出所有API服务
export default {
  auth: authApi,
  user: userApi,
  file: fileApi,
  system: systemApi,
  role: roleApi,
  storage: storageApi,
  apiManagement: apiManagementApi,
};
